const express = require('express')
const router = express.Router()

const contentCategoryController = require('../controller/ContentCategoryController')

/**
 * @api {get} /api/v1/content/category/list 获取文章分类列表
 * @apiDescription /api/v1/content/category/list
 * @apiName list
 * @apiGroup Category
 * @apiParam {string} [name]      分类名称
 * @apiParam {number} [status]    状态
 * @apiSampleRequest /api/v1/content/category/list
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {Category[]} data 文章分类信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 200 OK
 *  {
 *      "code" : 200,
 *      "data" : [
 *        {
            "categoryId": 1,
            "pid": 103,
            "name": "admin",
            "description": "kuake",
            "sort": 1,
            "email": "ry@163.com",
            "icon": "",
            "status": 1,
            "createdAt": "2023-09-01 12:22:33",
            "updatedAt": "1",
 *        }
 *      ],
 *      "message" : "请求成功",
 *  }
 * @apiVersion v1.0.0
 */
router.get('/list', contentCategoryController.categoryList)


/**
 * @api {get} /api/v1/content/category/:id 根据id查询文章分类信息
 * @apiDescription /api/v1/content/category/:id
 * @apiName getCategoryById
 * @apiGroup Category
 * @apiParam {number} id 文章分类id
 * @apiSampleRequest /api/v1/content/category/:id
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {Category} data 文章分类信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 204 OK
 *  {
 *      "code" : 204,
 *      "data" :  {
            "categoryId": 1,
            "pid": 103,
            "name": "admin",
            "description": "kuake",
            "sort": 1,
            "email": "ry@163.com",
            "icon": "",
            "status": 1,
            "createdAt": "2023-09-01 12:22:33",
            "updatedAt": "1",
 *        },
 *      "message" : "删除成功",
 *  }
 * @apiVersion v1.0.0
 */
router.get('/:id', contentCategoryController.selectCategoryById)


/**
 * @api {post} /api/v1/content/category/add 添加文章分类
 * @apiDescription /api/v1/content/category/add
 * @apiName add
 * @apiGroup Category
 * @apiBody {number} pid          父级id
 * @apiBody {string} name         分类名称
 * @apiBody {number} sort         排序
 * @apiBody {string} icon         分类图标
 * @apiBody {number} status       状态
 * @apiBody {string} description  描述
 * @apiSampleRequest /api/v1/content/category/add
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {Category[]} data 文章分类信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 201 OK
 *  {
 *      "code" : 201,
 *      "data" : true,
 *      "message" : "添加文章分类成功",
 *  }
 * @apiVersion v1.0.0
 */
router.post('/add', contentCategoryController.addCategory)


/**
 * @api {put} /api/v1/content/category/update 修改文章分类
 * @apiDescription /api/v1/content/category/update
 * @apiName update
 * @apiGroup Category
 * @apiBody {number} categoryId           分类id
 * @apiBody {number} pid          父级id
 * @apiBody {string} name         分类名称
 * @apiBody {number} sort         排序
 * @apiBody {string} icon         分类图标
 * @apiBody {number} status       状态
 * @apiBody {string} description  描述
 * @apiSampleRequest /api/v1/content/category/update
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {Category[]} data 文章分类信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 208 OK
 *  {
 *      "code" : 208,
 *      "data" : true,
 *      "message" : "修改成功",
 *  }
 * @apiVersion v1.0.0
 */
router.put('/update', contentCategoryController.updateCategory)


/**
 * @api {delete} /api/v1/content/category/delete 删除文章分类
 * @apiDescription /api/v1/content/category/delete
 * @apiName delete
 * @apiGroup Category
 * @apiBody {number} id 文章分类id
 * @apiSampleRequest /api/v1/content/category/delete
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {Category[]} data 文章分类信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 204 OK
 *  {
 *      "code" : 204,
 *      "data" : true,
 *      "message" : "删除成功",
 *  }
 * @apiVersion v1.0.0
 */
router.delete('/delete', contentCategoryController.deleteCategory)

module.exports = router